<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:pe="http://primefaces.org/ui/extensions"
	template="/WEB-INF/templates/template.xhtml">

	<ui:define name="headIncludes">
		<f:event listener="#{paisBean.initialize}" type="preRenderView"/>
	</ui:define>
	
	<ui:define name="pageName">Consultar País</ui:define>
	
	<ui:define name="buttons">
		<p:commandButton value="Novo" style="height:28px;" action="#{paisBean.changeToNew}" icon="ui-icon-plus"/>
	</ui:define>

	<ui:define name="content">
		<p:panel>
			<p:messages autoUpdate="true" id="messageListPais"/>
			<div>
				<h:panelGrid columns="7" >
					<h:outputText value="Filtrar por:" />
									
					<p:inputText id="inputSearchFilterCod" style="width:50px;" value="#{paisBean.filterPaisId}" maxlength="15" title="Código"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButton').click(); }">
						<pe:keyFilter regEx="/[\d]/" />
					</p:inputText>
					<p:watermark value="Código" for="inputSearchFilterCod"/>
					
					<p:inputText id="inputSearchFilterPais" style="width:300px;" 
						value="#{paisBean.filterPaisNome}" maxlength="50" title="País"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButton').click(); }"/>
					<p:watermark value="País" for="inputSearchFilterPais"/>
					
					<p:commandButton value="Consultar" style="height:28px;" id="searchButton"  action="#{paisBean.fillByFilter}"  icon="ui-icon-search"/>
				</h:panelGrid>	

				<div style="padding-top: 10px;" id="divTable">
					<p:dataTable var="pais" lazy="true"
						value="#{paisBean.paises}" id="tablePais" 
						paginator="true" rows="10" paginatorPosition="bottom"
						emptyMessage="Não há registros"
						selection="#{paisBean.currentPais}" selectionMode="single" rowKey="#{pais.id}">
						
						<p:ajax event="rowSelect" listener="#{paisBean.changeToDetail}"/>
						
						<p:column headerText="Código" style="width:100px;">
							<h:outputText value="#{pais.id}" />
						</p:column>
	
						<p:column headerText="País">
							<h:outputText value="#{pais.pais}" />
						</p:column>
	
						<p:column headerText="Sigla" width="50">
							<h:outputText value="#{pais.sigla}" />
						</p:column>
	
						<p:column headerText="DDI" width="50">
							<h:outputText value="#{pais.ddi}" />
						</p:column>
	
						<p:column headerText="" width="50">
							<p:commandButton icon="ui-icon-pencil"
								style="width: 24px; height: 24px;" action="#{paisBean.changeToEdit(pais.id)}" title="Editar"/>
							<p:spacer width="10px" />
							<p:commandButton icon="ui-icon-trash" action="#{paisBean.changeToDelete(pais.id)}" title="Excluir"
								style="width: 24px; height: 24px;" />
						</p:column>
					</p:dataTable>
				</div>
			</div>
		</p:panel>		
	</ui:define>
	<ui:define name="popups">
		<p:dialog appendToBody="true" modal="true" closable="false" widgetVar="popupConfirmDelete"
			width="300" resizable="false" header="Confirmação de exclusão" height="90">
			<h:form>
				<div style="margin-top: 10px;">
					<h:outputText value="Confirma a exclusão do registro?"/>
				</div>
				<div align="right" style="margin-top: 15px; margin-bottom: 15px;">
					<p:commandButton value="Excluir" actionListener="#{paisBean.remove}" oncomplete="popupConfirmDelete.hide()" icon="ui-icon-trash"/>
					<p:commandButton value="Cancelar" onclick="popupConfirmDelete.hide()" icon="ui-icon-cancel"/>
				</div>		
			</h:form>			
		</p:dialog>
	</ui:define>
</ui:composition>